﻿using System;
using Microsoft.Practices.Unity;
using Reactor.Client.ViewModel;
using Reactor.Client.Views;

namespace Reactor.Client.Services
{
    public interface IDialogService
    {
        void ShowAdoptServiceDialog();
        void ShowOrphanServiceDialog();
        void ShowTransferServiceDialog();
        void ShowUpgradeServiceDialog();
    }

    public class DialogService : IDialogService
    {
        private readonly IViewModelLocator _viewModelLocator;

        /// <summary>
        /// Initializes a new instance of the <see cref="DialogService"/> class.
        /// </summary>
        /// <param name="viewModelLocator">The view model locator.</param>
        public DialogService(IViewModelLocator viewModelLocator)
        {
            if (viewModelLocator == null) throw new ArgumentNullException("viewModelLocator");

            _viewModelLocator = viewModelLocator;
        }

        public void ShowAdoptServiceDialog()
        {
            var window = App.Container.Resolve<AdoptServiceWindow>();
            window.Show();
        }

        public void ShowOrphanServiceDialog()
        {
            var window = App.Container.Resolve<ModalDialog>();
            window.DataContext = _viewModelLocator.OrphanService;
            window.Show();
        }

        public void ShowTransferServiceDialog()
        {
            throw new NotImplementedException();
        }

        public void ShowUpgradeServiceDialog()
        {
            var window = App.Container.Resolve<ModalDialog>();
            window.DataContext = _viewModelLocator.UpgradeService;
            window.Show();
        }
    }
}
